package com.yan.demo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author taoge
 * @Date 2024/7/31 11:00
 * @Description
 */
public class Demo3 {
    public static void main(String[] args) {
        ArrayList<Student1> list = new ArrayList<>();
        list.add(new Student1("liusan" , 22 , 100.0));
        list.add(new Student1("lisi" , 21 , 90.0));
        list.add(new Student1("wangwu" , 20 , 96.0));
        list.add(new Student1("sanliu" , 18 , 80.0));
        ComparableImpl comparable = new ComparableImpl();
        comparable.sortName(list);
        list.forEach(item-> System.out.println(item));
    }
}

class ComparableImpl implements Comparable<Student1>{

    @Override
    public List<Student1> sortName(List<Student1> list) {
        for (int i = 0; i < list.size()-1; i++) {
            for (int j = 0; j < list.size()-1-i; j++) {
                if(list.get(j).getName().compareTo(list.get(j+1).getName()) > 0){
                    Student1 temp = list.get(j);
                    list.set(j , list.get(j+1));
                    list.set(j+1 , temp);
                }
            }
        }
        return list;
    }
}

interface Comparable<T>{
    List<T> sortName(List<T> list);
}
